home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
CHIP Turkiye Ekim 2000.iso
/
prog
/
naps
/
04
/
setup.exe
/
Gnucleus
/
PrefConnect.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-24
|
11KB
|
462 lines
/********************************************************************************
Gnucleus - A node application for the Gnutella network
Copyright (C) 2000 John Marshall
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For support, questions, comments, etc...
E-Mail:
swabby@c0re.net
Address:
21 Cadogan Way
Nashua, NH, USA 03062
********************************************************************************/
// PrefConnect.cpp : implementation file
//
#include "stdafx.h"
#include "Gnucleus.h"
#include "GnucleusDoc.h"
#include "PrefConnect.h"
#include "ViewSearch.h"
#include "GnuSock.h"
#include "GnuHash.h"
#include "GnuControl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrefConnect property page
IMPLEMENT_DYNCREATE(CPrefConnect, CPropertyPage)
CPrefConnect::CPrefConnect() : CPropertyPage(CPrefConnect::IDD)
{
Doc = NULL;
//{{AFX_DATA_INIT(CPrefConnect)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CPrefConnect::~CPrefConnect()
{
}
void CPrefConnect::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrefConnect)
DDX_Control(pDX, IDC_CHECK_DROP, m_chkDrop);
DDX_Control(pDX, IDC_EDIT_TIMEOUT, m_ebTimeout);
DDX_Control(pDX, IDC_EDIT_KEEP, m_ebKeep);
DDX_Control(pDX, IDC_CHECK_KEEP_CONNECT, m_chkKeep);
DDX_Control(pDX, IDC_EDIT_IP, m_ebIP);
DDX_Control(pDX, IDC_CHECK_IP, m_chkIP);
DDX_Control(pDX, IDC_CHECK_SPEED, m_chkSpeed);
DDX_Control(pDX, IDC_CHECK_PORT, m_chkPort);
DDX_Control(pDX, IDC_EDIT_PORT, m_ebPort);
DDX_Control(pDX, IDC_COMBO_SPEED, m_cmbSpeed);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPrefConnect, CPropertyPage)
//{{AFX_MSG_MAP(CPrefConnect)
ON_BN_CLICKED(IDC_CHECK_PORT, OnCheckIncomingPort)
ON_EN_CHANGE(IDC_EDIT_PORT, OnChangeEditIncomingPort)
ON_BN_CLICKED(IDC_CHECK_SPEED, OnCheckSpeed)
ON_CBN_EDITCHANGE(IDC_COMBO_SPEED, OnEditchangeComboSpeed)
ON_BN_CLICKED(IDC_CHECK_IP, OnCheckIp)
ON_EN_CHANGE(IDC_EDIT_IP, OnChangeEditIp)
ON_BN_CLICKED(IDC_CHECK_KEEP_CONNECT, OnCheckKeepConnect)
ON_EN_CHANGE(IDC_EDIT_KEEP, OnChangeEditKeep)
ON_EN_CHANGE(IDC_EDIT_TIMEOUT, OnChangeEditTimeout)
ON_BN_CLICKED(IDC_CHECK_DROP, OnCheckDrop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrefConnect message handlers
BOOL CPrefConnect::OnInitDialog()
{
CPropertyPage::OnInitDialog();
Doc = (CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc;
// Port selection
if(Doc->m_ConstPort == 0)
{
m_chkPort.SetCheck(0);
m_ebPort.EnableWindow(FALSE);
m_ebPort.SetWindowText("Random");
}
else
{
m_chkPort.SetCheck(1);
m_ebPort.SetWindowText( DWrdtoStr(Doc->m_ConstPort));
}
// Speed selection
m_cmbSpeed.InsertString(0, "T3 (or Greater)");
m_cmbSpeed.InsertString(0, "T1");
m_cmbSpeed.InsertString(0, "DSL");
m_cmbSpeed.InsertString(0, "Cable");
m_cmbSpeed.InsertString(0, "ISDN-128K");
m_cmbSpeed.InsertString(0, "ISDN-56K");
m_cmbSpeed.InsertString(0, "56K Modem");
m_cmbSpeed.InsertString(0, "33.6 Modem");
m_cmbSpeed.InsertString(0, "28.8 Modem");
m_cmbSpeed.InsertString(0, "14.4 Modem");
m_cmbSpeed.InsertString(0, "");
if(Doc->m_ConnectSpeed)
{
m_chkSpeed.SetCheck(1);
CString speed_string = GetSpeedString(Doc->m_ConnectSpeed);
m_cmbSpeed.SetWindowText( speed_string.IsEmpty() ? DWrdtoStr(Doc->m_ConnectSpeed) : speed_string);
}
else
{
m_chkSpeed.SetCheck(0);
m_cmbSpeed.EnableWindow(FALSE);
m_cmbSpeed.SetWindowText( DWrdtoStr(Doc->m_EstSpeed) );
}
// Local IP
if(Doc->m_ForceIP.a == 0 && Doc->m_ForceIP.b == 0 && Doc->m_ForceIP.c == 0 && Doc->m_ForceIP.d == 0)
{
m_chkIP.SetCheck(0);
m_ebIP.EnableWindow(FALSE);
m_ebIP.SetWindowText( Doc->GnuComm->localHost );
}
else
{
m_chkIP.SetCheck(1);
m_ebIP.SetWindowText( IPtoStr(Doc->m_ForceIP) );
}
// Connect preference
if(Doc->m_MonitorType == 0)
{
m_chkKeep.SetCheck(0);
((CButton *) GetDlgItem(IDC_RADIO_LESS))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_RADIO_EXACT))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_RADIO_MORE))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_RADIO_MORE))->SetCheck(1);
m_ebKeep.SetWindowText( DWrdtoStr(Doc->m_ConnectNum) );
m_ebKeep.EnableWindow(FALSE);
}
else
{
m_chkKeep.SetCheck(1);
if(Doc->m_MonitorType == 1)
((CButton *) GetDlgItem(IDC_RADIO_LESS))->SetCheck(1);
else if(Doc->m_MonitorType == 2)
((CButton *) GetDlgItem(IDC_RADIO_EXACT))->SetCheck(1);
else if(Doc->m_MonitorType == 3)
((CButton *) GetDlgItem(IDC_RADIO_MORE))->SetCheck(1);
else
((CButton *) GetDlgItem(IDC_RADIO_MORE))->SetCheck(1);
m_ebKeep.SetWindowText( DWrdtoStr(Doc->m_ConnectNum));
}
// Timeout length
m_ebTimeout.SetWindowText( DWrdtoStr(Doc->m_TimeoutConnect) );
// Drop established for incoming
m_chkDrop.SetCheck(Doc->m_DropForIncoming);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPrefConnect::OnCheckIncomingPort()
{
if(m_chkPort.GetCheck())
{
m_ebPort.EnableWindow();
m_ebPort.SetWindowText("");
}
else
{
m_ebPort.EnableWindow(FALSE);
m_ebPort.SetWindowText("Random");
}
SetModified();
}
void CPrefConnect::OnChangeEditIncomingPort()
{
SetModified();
}
void CPrefConnect::OnCheckSpeed()
{
if(m_chkSpeed.GetCheck())
{
m_cmbSpeed.EnableWindow();
m_cmbSpeed.SetWindowText("");
}
else
{
m_cmbSpeed.EnableWindow(FALSE);
m_cmbSpeed.SetWindowText( DWrdtoStr(Doc->m_EstSpeed) );
}
SetModified();
}
void CPrefConnect::OnEditchangeComboSpeed()
{
SetModified();
}
void CPrefConnect::OnCheckIp()
{
if(m_chkIP.GetCheck())
{
m_ebIP.EnableWindow();
m_ebIP.SetWindowText("");
}
else
{
m_ebIP.EnableWindow(FALSE);
m_ebIP.SetWindowText( Doc->GnuComm->localHost );
}
SetModified();
}
void CPrefConnect::OnChangeEditIp()
{
SetModified();
}
void CPrefConnect::OnCheckKeepConnect()
{
if(m_chkKeep.GetCheck())
{
((CButton *) GetDlgItem(IDC_RADIO_LESS))->EnableWindow();
((CButton *) GetDlgItem(IDC_RADIO_EXACT))->EnableWindow();
((CButton *) GetDlgItem(IDC_RADIO_MORE))->EnableWindow();
m_ebKeep.EnableWindow();
}
else
{
((CButton *) GetDlgItem(IDC_RADIO_LESS))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_RADIO_EXACT))->EnableWindow(FALSE);
((CButton *) GetDlgItem(IDC_RADIO_MORE))->EnableWindow(FALSE);
m_ebKeep.EnableWindow(FALSE);
}
SetModified();
}
void CPrefConnect::OnChangeEditKeep()
{
SetModified();
}
void CPrefConnect::OnChangeEditTimeout()
{
SetModified();
}
void CPrefConnect::OnCheckDrop()
{
SetModified();
}
BOOL CPrefConnect::OnApply()
{
CString store;
// Port selection
if(m_chkPort.GetCheck())
{
m_ebPort.GetWindowText(store);
if( atol(store) )
Doc->m_ConstPort = (DWORD) atol(store);
if(Doc->m_ConstPort != Doc->GnuComm->localPort)
{
Doc->GnuComm->localPort = Doc->m_ConstPort;
Doc->GnuComm->StartListening();
}
}
else
{
if(Doc->m_ConstPort)
{
Doc->GnuComm->localPort = rand() % 22500 + 2500;
Doc->GnuComm->StartListening();
}
Doc->m_ConstPort = 0;
}
// Speed Selection
if(m_chkSpeed.GetCheck())
{
m_cmbSpeed.GetWindowText(store);
Doc->m_ConnectSpeed = GetSpeedinBytes(store);
}
else
Doc->m_ConnectSpeed = 0;
// IP Selection
if(m_chkIP.GetCheck())
{
m_ebIP.GetWindowText(store);
Doc->m_ForceIP = StrtoIP(store);
}
else
{
Doc->m_ForceIP.a = 0;
Doc->m_ForceIP.b = 0;
Doc->m_ForceIP.c = 0;
Doc->m_ForceIP.d = 0;
}
// Connect preference
if(m_chkKeep.GetCheck())
{
if( ((CButton *) GetDlgItem(IDC_RADIO_LESS))->GetCheck() )
Doc->m_MonitorType = 1;
else if( ((CButton *) GetDlgItem(IDC_RADIO_EXACT))->GetCheck() )
Doc->m_MonitorType = 2;
else if( ((CButton *) GetDlgItem(IDC_RADIO_MORE))->GetCheck() )
Doc->m_MonitorType = 3;
else
Doc->m_MonitorType = 0;
m_ebKeep.GetWindowText(store);
Doc->m_ConnectNum = atoi(store);
}
else
{
Doc->m_MonitorType = 0;
}
// Timeout length
m_ebTimeout.GetWindowText(store);
if( atoi(store) )
Doc->m_TimeoutConnect = atoi(store);
else
Doc->m_TimeoutConnect = 4;
// Drop established for incoming
if(m_chkDrop.GetCheck())
Doc->m_DropForIncoming = 1;
else
Doc->m_DropForIncoming = 0;
return CPropertyPage::OnApply();
}
DWORD CPrefConnect::GetSpeedinBytes(CString Speed)
// The protocol is messed, bytes are bits
{
if(Speed == "")
return 0;
if(Speed == "14.4 Modem")
return 14;
if(Speed == "28.8 Modem")
return 29;
if(Speed == "33.6 Modem")
return 33;
if(Speed == "56K Modem")
return 53;
if(Speed == "ISDN-56K")
return 56;
if(Speed == "ISDN-128K")
return 128;
if(Speed == "Cable")
return 384;
if(Speed == "DSL")
return 768;
if(Speed == "T1")
return 1500;
if(Speed == "T3 (or Greater)")
return 45000;
return atol(Speed);
}
CString CPrefConnect::GetSpeedString(DWORD _dw_speed)
// The protocol is messed, bytes are bits
{
// limit to only those speeds returned by GetSpeedinBytes
switch(_dw_speed)
{
case 14:
return "14.4 Modem";
case 29:
return "28.8 Modem";
case 33:
return "33.6 Modem";
case 53:
return "56K Modem";
case 56:
return "ISDN-56K";
case 128:
return "ISDN-128K";
case 384:
return "Cable";
case 768:
return "DSL";
case 1500:
return "T1";
case 45000:
return "T3 (or Greater)";
default:
return "";
}
}
/*
// Timeout length
m_ebTimeout.SetWindowText( DWrdtoStr(Doc->m_TimeoutConnect) );
// Drop established for incoming
m_chkDrop.SetCheck(Doc->m_DropForIncoming);
*/